package com.niodata.dp.app.dao;

import com.niodata.dp.app.AppInfo;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface AppInfoMapper {

  @Insert("insert into APP_INFO(APP_ID,OWNER_TYPE,OWNER_ID,NAME,DESCRIPTION,APP_CODE,OWNER) VALUES"
      + "(#{appInfo.appId},#{appInfo.ownerType},#{appInfo.ownerId},#{appInfo.name},"
      + "#{appInfo.description},#{appInfo.appCode},#{appInfo.ownerName})")
  public void save(@Param("appInfo") AppInfo appInfo);

  @Delete("delete from APP_INFO where APP_ID=#{appId}")
  public void delete(@Param("appId") String appId);

  @Select("select * from APP_INFO WHERE APP_CODE=#{appCode}")
  @ResultMap("appInfoResultMap")
  public AppInfo getByCode(@Param("appCode") String appCode);

  @Update("update APP_INFO set DESCRIPTION=#{appInfo.description},"
      + "NAME=#{appInfo.name} where APP_ID=#{appInfo.appId}")
  public void update(@Param("appInfo") AppInfo appInfo);

  public List<AppInfo> findUserAuthorizedApps(@Param("userId") long userId, @Param("offset")
      int offset, @Param("count") int count, @Param("keyWord") String keyWord);

  public AppInfo getByAppId(String appId);

  public List<AppInfo> findUserApps(@Param("userId") long userId, @Param("keyWord") String keyWord);

}
